package com.stars.empoly.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.empoly.adapter.InvoiceOrderAdapter
import com.stars.empoly.base.MBRActivity
import com.stars.empoly.databinding.ActivityInvoiceOrderBinding
import com.stars.empoly.model.CompreBean
import com.stars.empoly.vmodel.InvoiceOrderVModel
import com.trailer.base.net.IResp

/**
 * 发票-选择订单
 *on 2021/5/9
 */
class InvoiceOrderActivity : MBRActivity<InvoiceOrderVModel, InvoiceOrderAdapter, ActivityInvoiceOrderBinding>(){


    override fun listeners() {
        super.listeners()

        binding.llSubmit.onClick {
            //提交
            var list=adapter().data as List<CompreBean>
            if(null!=list&& list.isNotEmpty()){

                var ss=""
                for(item in list){
                    if(item.chose){
                        ss = if(TextUtils.isEmpty(ss)){
                            item.id
                        }else{
                            ss+","+item.id
                        }

                    }
                }

                val intent = Intent()
                var bundle= Bundle()
                bundle.putString("order_ids",ss)
                intent.putExtras(bundle)
                setResult(Activity.RESULT_OK, intent)
                finish()


            }else{
                toast("没有订单选择")
            }
        }
    }

    override fun onListReceive(res: IResp<*>) {
        super.onListReceive(res)

        if (null != res) {

            var list = res.data() as List<CompreBean>
            if (list.isEmpty() && vm.repository().page == 1) {

                binding.listEmpty.visibility = View.VISIBLE
            } else {
                binding.listEmpty.visibility = View.GONE
            }

        }
    }

    override fun title(): String? {
        return "选择订单"
    }
    override fun vmClass(): Class<InvoiceOrderVModel> {
        return InvoiceOrderVModel::class.java
    }
    override fun binding(): ActivityInvoiceOrderBinding {
        return ActivityInvoiceOrderBinding.inflate(layoutInflater)
    }

    override fun initAdapter(): InvoiceOrderAdapter {
        return InvoiceOrderAdapter(vm)
    }
}
